package com.ars.common.servlet.Login;

import com.ars.common.utils.DBUtil;
import com.ars.common.beans.User.User;

import java.sql.PreparedStatement;
import java.sql.SQLException;

public class getLogUser {
    public static User getUser(String id) throws SQLException {
        User user = new User();

        DBUtil dbUtil = new DBUtil();
        String sql = "select * from user where userID = ? ";
        PreparedStatement ps = DBUtil.getConnection().prepareStatement(sql);
        ps.setString(1, id);
        ps.executeQuery();
        while (ps.getResultSet().next()) {
            user.setUserID(ps.getResultSet().getString("userID"));
            user.setPassword(ps.getResultSet().getString("password"));
            user.setName(ps.getResultSet().getString("name"));
            user.setSex(ps.getResultSet().getString("sex"));
            user.setAdminID(ps.getResultSet().getString("isAdmin"));
            user.setRole(ps.getResultSet().getString("role"));
//            user.setAdminName(ps.getResultSet().getString("adminName"));
            user.setPhone(ps.getResultSet().getString("phone"));
            user.setMailbox(ps.getResultSet().getString("mailbox"));
        }
        return user;
    }
}
